
#ifndef _FIFO2_H_
#define _FIFO2_H_

#include <stdint.h>

typedef uint8_t elem_t;

struct kfifo {
	elem_t *buffer;	/* the buffer holding the data */
	unsigned int size;	/* the size of the allocated buffer */
	unsigned int in;	/* data is added at offset (in % size) */
	unsigned int out;	/* data is extracted from off. (out % size) */
};

typedef struct kfifo fifo_t;

static inline unsigned int fifo_data_length(const fifo_t *fifo)
{
	return fifo->in - fifo->out;
}

static inline unsigned int fifo_free_space(const fifo_t *fifo)
{
	return fifo->size - fifo_data_length(fifo);
}

static inline void fifo_clean(fifo_t *fifo)
{
	fifo->in = fifo->out = 0;
}

fifo_t *fifo_init(fifo_t *fifo, elem_t *buffer, unsigned int size);
unsigned int fifo_get_block(fifo_t *fifo, elem_t *buffer, unsigned int len);
unsigned int fifo_put_block(fifo_t *fifo, const elem_t *buffer, unsigned int len);
unsigned int fifo_put(fifo_t *fifo, elem_t *elem);
unsigned int fifo_get(fifo_t *fifo, elem_t *elem);


#endif
